<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Error History</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f4f4f4;
            margin: 0;
            padding: 0;
        }

        .container {
            max-width: 1200px;
            margin: 0 auto;
            padding: 20px;
            background-color: #fff;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
            border-radius: 5px;
        }

        h1 {
            text-align: center;
            margin-bottom: 20px;
            color: #333;
        }

        table {
            width: 100%;
            border-collapse: collapse;
            border: 1px solid #ccc;
            margin-top: 20px;
        }

        thead {
            background-color: #f2f2f2;
        }

        th, td {
            padding: 10px;
            text-align: left;
            border-bottom: 1px solid #ccc;
        }

        th {
            font-weight: bold;
        }

        tr:hover {
            background-color: #f2f2f2;
        }

        th:nth-child(1), td:nth-child(1) {
            width: 10%
        }
        th:nth-child(2), td:nth-child(2) {
            width: 20%;
        }

        th:nth-child(3), td:nth-child(3) {
            width: 25%;
        }

        th:nth-child(4), td:nth-child(4) {
            width: 35%;
        }

        th:nth-child(5), td:nth-child(5) {
            width: 10%;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>Error History</h1>
        <table border="1">
            <thead>
                <tr>
                    <th>ID</th>
                    <th>Time</th>
                    <th>Type</th>
                    <th>Info</th>
                    <th>Link</th>
                </tr>
            </thead>
            <tbody id="errorTableBody">
                <!--表格内容将通过JavaScript自动填入-->
            </tbody>
        </table>
    </div>

        <script>
        // 使用Fetch API加载JSON文件
        fetch('../error_report/data')
            .then(response => response.json())
            .then(data => {
                // 获取表格的tbody元素
                var tableBody = document.getElementById("errorTableBody");

                // 遍历JSON数据并填充到表格中
                var keys_list = Object.keys(data);
                for (var i = keys_list.length-1; i>=0; i--) {
                    id = keys_list[i];
                    var rowData = data[id];
                    var newRow = document.createElement("tr");

                    // 创建并填充单元格
                    var idCell = document.createElement("td");
                    idCell.textContent = id;
                    newRow.appendChild(idCell)

                    var timeCell = document.createElement("td");
                    timeCell.textContent = rowData[0];
                    newRow.appendChild(timeCell);

                    var typeCell = document.createElement("td");
                    typeCell.textContent = rowData[1];
                    newRow.appendChild(typeCell);

                    var infoCell = document.createElement("td");
                    infoCell.textContent = rowData[2];
                    newRow.appendChild(infoCell);

                    var urlCell = document.createElement("td");
                    urlCell.innerHTML = "<a href=\"http://180.166.0.98:1458/error_report/error?id="+id+"\">View</a>";
                    newRow.appendChild(urlCell);

                    // 将新行添加到表格中
                    tableBody.appendChild(newRow);
                }
            })
            .catch(error => {
                console.error('Failed to load JSON data: ' + error);
            });
    </script>
</body>
</html>
